//begin of create.js
var pages = pages || {};
(function(p) {
  p.create = {
    init: function() {
      $('.submit').on('click', function() {
        _submitShare();
      });
    }
  };
  //local functions
  //inner functions
  function _submitShare() {
    var sFuncName = $("[name='funcname']").val();
    var sCodeLanguage = $("[name='codetype']").val();
    var sFuncType = $("[name='functype']").val();
    var sCode = $("[name='code']").val();
    var sCreator = $("[name='email']").val();
    if (sFuncName.length > 0 && sCodeLanguage.length > 0 && sFuncType.length && sCode.length > 0 && sCreator.length > 0) {
      //
    } else {
      alert('请填写完整信息！');
      return;
    }
    //调整发布按钮的文字
    $('.submit').attr('disabled', 'disabled');
    $('.submit').val('正在提交..')
    $.ajax({
      url: "api.asp",
      type: "post",
      data: {
        "action": "submit_newcode",
        "funcName": sFuncName,
        "funcLan": sCodeLanguage,
        "funcType": sFuncType,
        "funcCode": sCode,
        "CreatorMail": sCreator
      },
      success: function(data) {
        var oRet = pages.common.parseJSON(data);
        if (oRet) {
          if (oRet.ref == "ok") {
            if (oRet.id == '-1') {
              pages.common.control.goTo('/');
            } else {
              pages.common.control.goTo('/show.asp?id=' + oRet.id);
            }
          }
        }
        $('.submit').removeAttr('disabled');
        $('.submit').val('发布分享')
      }
    });
  }
})(pages);
//end of create.js